﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeiDuan.Model;
using WeiDuan.Service;
using B2B.Service;
using B2B.Business;
using B2B.Business.Impl;
using Autofac;

namespace B2B.Service.Impl
{
    [WeiDuanService(Name = "B2B.ProductClassService", Description = "商品类别")]
    public class ProductClassService : BaseService, IProductClassService, IAppService
    {
        private IProductClassBusiness mBusiness = null;

        public ProductClassService()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<B2B.Business.Impl.ProductClassBusiness>().As<IProductClassBusiness>();
            using (var container = builder.Build())
            {
                mBusiness = container.Resolve<IProductClassBusiness>();
            }
            base.eventCreate += ProductClassService_eventCreate;
        }

        void ProductClassService_eventCreate(IWeiDuanService service)
        {
            if (mBusiness is IServiceInjection)
                ((IServiceInjection)mBusiness).Injection(mWeiDuanService);
        }

        [WeiDuanInterface(Name = "AddClass", Description = "添加类别")]
        public string AddClass(ClassAddRequest req, UserInfo user)
        {
            return mBusiness.AddClass(req, user);
        }

        [WeiDuanInterface(Name = "UpdateClass", Description = "修改类别")]
        public void UpdateClass(ClassUpdateRequest req, UserInfo user)
        {
            mBusiness.UpdateClass(req, user);
        }

        [WeiDuanInterface(Name = "RemoveClass", Description = "删除类别")]
        public void RemoveClass(string id, UserInfo user)
        {
            mBusiness.RemoveClass(id, user);
        }

        [WeiDuanInterface(Name = "ChangeClassSort", Description = "修改类别排序")]
        public void ChangeClassSort(List<ObjectSort> req, UserInfo user)
        {
            mBusiness.ChangeClassSort(req, user);
        }

        [WeiDuanInterface(Name = "QueryClass", Description = "查询所有类别数据")]
        public List<ClassInfo> QueryClass(UserInfo user)
        {
            return mBusiness.QueryClass(user);
        }

        [WeiDuanInterface(Name = "QueryClassStru", Description = "查询所有数据数据，并按树形结构返回。")]
        public List<ClassInfo> QueryClassStru(UserInfo user)
        {
            return mBusiness.QueryClassStru(user);
        }

        [WeiDuanInterface(Name = "QueryChildClass", Description = "查询指定类别下的所有子类")]
        public List<ClassInfo> QueryChildClass(string parentId, UserInfo user)
        {
            return mBusiness.QueryChildClass(parentId, user);
        }

        [WeiDuanInterface(Name = "QueryChildClassStru", Description = "查询指定类别下的所有子类，按树形结构返回")]
        public List<ClassInfo> QueryChildClassStru(string parentId, UserInfo user)
        {
            return mBusiness.QueryChildClassStru(parentId, user);
        }

        [WeiDuanInterface(Name = "AddClassAttr", Description = "添加类别属性")]
        public string AddClassAttr(ClassAttrAddRequest req, UserInfo user)
        {
            return mBusiness.AddClassAttr(req, user);
        }

        [WeiDuanInterface(Name = "UpdateClassAttr", Description = "修改类别属性")]
        public void UpdateClassAttr(ClassAttrUpdateRequest req, UserInfo user)
        {
            mBusiness.UpdateClassAttr(req, user);
        }

        [WeiDuanInterface(Name = "RemoveClassAttr", Description = "删除一个类属性")]
        public void RemoveClassAttr(string id, UserInfo user)
        {
            mBusiness.RemoveClassAttr(id, user);
        }

        [WeiDuanInterface(Name = "ChangeClassAttrSort", Description = "修改类别属性的排序")]
        public void ChangeClassAttrSort(List<ObjectSort> req, UserInfo user)
        {
            mBusiness.ChangeClassAttrSort(req, user);
        }

        [WeiDuanInterface(Name = "QueryClassAttr", Description = "按类别查询属性")]
        public List<ClassAttrInfo> QueryClassAttr(string id, UserInfo user)
        {
            return mBusiness.QueryClassAttr(id, user);
        }

        [WeiDuanInterface(Name = "AddClassAttrValue", Description = "添加类别属性值")]
        public string AddClassAttrValue(ClassAttrValueAddRequest req, UserInfo user)
        {
            return mBusiness.AddClassAttrValue(req, user);
        }

        [WeiDuanInterface(Name = "UpdateClassAttrValue", Description = "修改类别属性值")]
        public void UpdateClassAttrValue(ClassAttrValueUpdateRequest req, UserInfo user)
        {
            mBusiness.UpdateClassAttrValue(req, user);
        }

        [WeiDuanInterface(Name = "RemoveClassAttrValue", Description = "删除一个类别属性值")]
        public void RemoveClassAttrValue(string classId, UserInfo user)
        {
            mBusiness.RemoveClassAttrValue(classId, user);
        }

        [WeiDuanInterface(Name = "ChangeClassAttrValueSort", Description = "修改类别属性值的排序")]
        public void ChangeClassAttrValueSort(List<ObjectSort> req, UserInfo user)
        {
            mBusiness.ChangeClassAttrValueSort(req, user);
        }

        [WeiDuanInterface(Name = "QueryClassAttrValue", Description = "按类别属性ID查询所有属性值")]
        public List<ClassAttrValueInfo> QueryClassAttrValue(string attrId, UserInfo user)
        {
            return mBusiness.QueryClassAttrValue(attrId, user);
        }

        [WeiDuanInterface(Name = "AddBrand", Description = "添加品牌")]
        public string AddBrand(BrandAddRequest req, UserInfo user)
        {
            return mBusiness.AddBrand(req, user);
        }

        [WeiDuanInterface(Name = "UpdateBrand", Description = "修改品牌")]
        public void UpdateBrand(BrandUpdateRequest req, UserInfo user)
        {
            mBusiness.UpdateBrand(req, user);
        }

        [WeiDuanInterface(Name = "RemoveBrand", Description = "删除品牌")]
        public void RemoveBrand(string id, UserInfo user)
        {
            mBusiness.RemoveBrand(id, user);
        }

        [WeiDuanInterface(Name = "QueryBrandByClass", Description = "按类别查询品牌")]
        public List<BrandInfo> QueryBrandByClass(string id, UserInfo user)
        {
            return mBusiness.QueryBrandByClass(id, user);
        }
    }
}
